package LeetCode;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class LC_575_DistributeCandies {

    public static void main(String[] args) {

    }

    public class Solution {
        public int distributeCandies(int[] candies) {
            Set<Integer> s = new HashSet<>();
            for (int candy : candies) {
                if (!s.contains(candy)) {
                    s.add(candy);
                }
            }
            return s.size() < (candies.length / 2) ? s.size() : (candies.length / 2);
        }
    }

    public class Solution_2 {
        public int distributeCandies(int[] candies) {
            Arrays.sort(candies);
            int res = 0;
            for (int i = 0; i < candies.length; i++) {
                if (i == 0 || candies[i] != candies[i - 1]) {
                    res++;
                }
            }
            return Math.min(res, candies.length / 2);
        }
    }

}